home *** CD-ROM | disk | FTP | other *** search
- // GENTREE.CPP - GENERIC TREE Traversal utility
- // CopyRight (c) by Paul Kimmel 1994
- // All Rights Reserved.
- //
-
-
- #include <process.h>
- #include <stdlib.h>
- #include <dos.h>
- #include <string.h>
- #include <dir.h>
- #include <mem.h>
- #include <stdio.h>
- #include <conio.h>
-
-
- #include "gentree.h"
-
-
- extern unsigned _stklen = 65536U;
- char start[MAXPATH];
-
- void (*func)(); // generic function
- void traverse( char* pname = "*.*" ); // traversal function
- int c_break(void);
-
-
-
-
- // The general tree starting point
- void GenTree( void (*f)(), char* startPath )
- {
- func = f;
-
- ctrlbrk( c_break ); // set ctrl-brk handler
- memset( start, (int) 'P', MAXPATH ); // initialize path buffer
- strcpy( start, startPath ); // copy path
- traverse( start ); // start recursive function
-
- }
-
- #define ABORT 0
-
- int c_break(void)
- {
- return(ABORT);
- }
-
-
- // Traverse the tree recursively
-
- void traverse( char* pname )
- {
- struct ffblk ffblk;
-
- if (kbhit()) exit;
-
- chdir( pname ); // change to subdirectory
- func();
-
- int done;
- done = findfirst("*.*", &ffblk, FA_DIREC);
-
- // get all of the sub-directories
- while (!done){
-
- if( strcmp(ffblk.ff_name, "..") != 0 && strcmp(ffblk.ff_name, ".") != 0
- && ffblk.ff_attrib == FA_DIREC)
- {
- printf(" %s\n", ffblk.ff_name);
-
- // call the generic function
- traverse( ffblk.ff_name );
- }
- done = findnext(&ffblk);
- }
-
- chdir("..");
- }
-
-